package com.cy.pj.sys.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.sys.pojo.SysGoods;
import com.cy.pj.sys.service.SysGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods/")
public class SysGoodsController {

	@Autowired
	private SysGoodsService sysGoodsService;

	@RequestMapping("doDeleteById")
	public JsonResult doDeleteById(Long id){
		sysGoodsService.deleteById(id);
		return new JsonResult("删除成功");
	}


	@RequestMapping("doUpdateObject")
	public JsonResult doUpdateObject(SysGoods goods){
		sysGoodsService.updateObject(goods);
		return new JsonResult("修改商品成功");
	}

	@RequestMapping("doFindObjectById")
	public JsonResult doFindObjectById(Long id){
		return sysGoodsService.doFindObjectById(id);
	}

	@RequestMapping("doSaveObject")
	public JsonResult doSaveObject(SysGoods goods){
		sysGoodsService.saveObject(goods);
		return new JsonResult("添加成功");
	}

	@RequestMapping("doFindType")
	public JsonResult doFindType(){
		return sysGoodsService.doFindType();
	}

	@RequestMapping("doValidById")
	public JsonResult doValidById(Long id,Integer valid) {
		System.out.println(valid);
		sysGoodsService.validById(id, valid);
		return new JsonResult("update ok");
	}

	@RequestMapping("doFindPageObjects")
	public JsonResult doFindPageObjects(String goodsname,Integer pageCurrent) {
		return new JsonResult(sysGoodsService.findPageObjects(goodsname, pageCurrent));
	}
}
